# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Johannes Löthberg <johannes@kyriasis.com>
# Contributor: Piotr Gorski <lucjan.lucjanov@gmail.com>
# Contributor: Lucy <lucy@luz.lu>
# Contributor: Bartlomiej Piotrowski <nospam@bpiotrowski.pl>

pkgname=pkgconf
pkgver=2.1.0
pkgrel=2
pkgdesc="Package compiler and linker metadata toolkit"
url="https://gitea.treehouse.systems/ariadne/pkgconf"
license=(custom:ISC)
arch=(loong64 x86_64)
depends=(
  glibc
  sh
)
makedepends=(
  git
  meson
)
provides=(
  libpkgconf.so
  pkg-config
  pkgconfig
)
conflicts=(pkg-config)
replaces=(pkg-config)
_commit=61d39ad899867713e73752cf23c40f0275bf71c3  # tags/pkgconf-2.1.0
source=(
  "git+$url#commit=$_commit"
  {x86_64,i686}-pc-linux-gnu.personality
  loongarch64-unknown-linux-gnu.personality
)
b2sums=('SKIP'
        'c04583e19149c1035cb7777a59f0fbc4988b672d8e45105e33def3d0f9054464e33a400a3e7c7e8b99b334e4fe06aaa9d7e34662e806096d4374bd6b12d803db'
        '94c8fd12b5f33611fd6dbeae03b20e72bcf2937e764766e2633b2fd4c14925860d57eee234016c81b0563a47b112ac9ef4a8b3bb9fa3fc0dd266f355bc156c58'
        '335aac01ee674f3d0d4d895145fa0fba29f053338ab6d5f9225a16d6f25de841ec812a77dc9bdd6fa7f0fe7a1f4e47cd6762540700741874a6190b3e41c5222e')

pkgver() {
  cd pkgconf
  git describe --tags | sed 's/^pkgconf-//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd pkgconf

  # Fix --modversion (broke WebKitGTK build)
  # https://github.com/pkgconf/pkgconf/issues/317
  # https://github.com/pkgconf/pkgconf/issues/332
  git revert -n 97d907ba93b7e4eef67e4c0a80939421ad3183f0
}

build() {
  local meson_options=(
    -D tests=disabled  # Tests need kyua
  )

  arch-meson pkgconf build "${meson_options[@]}"
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

package() {
  meson install -C build --destdir "$pkgdir"

  local p
  if [[ $CARCH == loong64 ]];then
    install -Dt "$pkgdir/usr/share/pkgconfig/personality.d" -m644 \
      loongarch64-unknown-linux-gnu.personality
    ln -s pkgconf "$pkgdir/usr/bin/loongarch64-unknown-linux-gnu-pkg-config"
  else
    for p in {x86_64,i686}-pc-linux-gnu; do
      install -Dt "$pkgdir/usr/share/pkgconfig/personality.d" -m644 $p.personality
      ln -s pkgconf "$pkgdir/usr/bin/$p-pkg-config"
    done
  fi

  ln -s pkgconf "$pkgdir/usr/bin/pkg-config"
  ln -s pkgconf.1 "$pkgdir/usr/share/man/man1/pkg-config.1"

  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 pkgconf/COPYING
}

# vim:set sw=2 sts=-1 et:
